package com.szq.pattern;

import com.szq.pattern.event.EventManager;
import com.szq.pattern.event.listener.MQEventListener;
import com.szq.pattern.event.listener.MessageEventListener;

/**
 * @description:
 * @author: szq
 * @date: 2021-09-13 13:06:54
 */
public abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService(){
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
        eventManager.subscribe(EventManager.EventType.Message, new MessageEventListener());
    }

    public LotteryResult draw(String id){
        LotteryResult lotteryResult = doDraw(id);
        eventManager.notify(EventManager.EventType.MQ, lotteryResult);
        eventManager.notify(EventManager.EventType.Message, lotteryResult);
        return lotteryResult;
    }

    protected abstract LotteryResult doDraw(String uId);
}
